using System;
using CastleSample.Business.Interface;
using CastleSample.Core;
using CastleSample.Entity;

namespace CastleSample.Business.Remoting.Server
{
    [Serializable]
    public abstract class BizServiceProxyBase<T> : MarshalByRefObject, IBizService where T : IBizService
    {
        public BizServiceProxyBase()
        {
            m_BizServiceLocal = ServiceLocator.Get<T>(typeof (T).Name + "Local");
        }

        private T m_BizServiceLocal;

        protected virtual T BizServiceLocal
        {
            get { return m_BizServiceLocal; }
            set { m_BizServiceLocal = value; }
        }

        public virtual UserContext CurrentUserContext
        {
            get { return BizServiceLocal == null ? null : BizServiceLocal.CurrentUserContext; }
            set
            {
                if (BizServiceLocal != null)
                {
                    BizServiceLocal.CurrentUserContext = value;
                }
                ;
            }
        }
    }
}